import math

c = 0
b = int(input())
p = str(b)
w = len(p)
if w == 4:
    y = p[0] + p[1]
    t = int(y)
    for k in range(2, int(math.sqrt(t) + 1)):
        if t % k == 0:
            break
    else:
        w1 = t
    h = p[2]
    m = int(h)
    for k in range(2, int(math.sqrt(m) + 1)):
        if m % k == 0:
            break
    else:
        w2 = m
        if w2 > c:
            c = w2
        else:
            c = c
    n = p[1] + p[2]
    g = int(n)
    for k in range(2,int(math.sqrt(g) + 1)):
        if g % k == 0:
            break
    else:
        w3 = g
        if w2 > w3:
            c = w2
        else:
            c = w3
    f = p[1]
    q = int(f)
    for k in range(2, int(math.sqrt(q) + 1)):
        if q % k == 0:
            break
    else:
        w4 = q
        if w4 > c:
            c = w4
        else:
            c = c
    v = p[0] + p[1] + p[2]
    s = int(v)
    for k in range(2,int(math.sqrt(s) + 1)):
        if s % k == 0:
            break
    else:
        w5 = s
        if w5 > c:
            c = w5
        else:
            c = c
    x = p[0]
    d = int(x)
    for k in range(2, int(math.sqrt(d) + 1)):
        if d % k == 0:
            break
    else:
        w6 = d
        if w6 > c:
            c = w6
        else:
            c = c
    o = p[1] + p[2] + p[3]
    a = int(o)
    for k in range(2,int(math.sqrt(a) + 1)):
        if a % k == 0:
            break
    else:
        w7 = a
        if w7 > c:
            c = w7
        else:
            c = c
    u = p[2] + p[3]
    r = int(u)
    for k in range(2, int(math.sqrt(r) + 1)):
        if r % k == 0:
            break
    else:
        w8 = r
        if w8 > c:
            c = w8
        else:
            c = c
    i = p[0] + p[1] + p[2] + p[3]
    e = int(i)
    for k in range(2, int(math.sqrt(e) + 1)):
        if e % k == 0:
            break
    else:
        w9 = e
        if w9 > c:
            c = w9
        else:
            c = c
    z = p[3]
    l = int(z)
    for k in range(2,int(math.sqrt(l) + 1)):
        if l % k == 0:
            break
    else:
        w10 = l
        if w10 > c:
            c = w10
        else:
            c = c
    print(c)
else:
    print('0')